package com.baizhi.springbootshiro.utils;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
 * @author Administrator
 */
@Slf4j
@Aspect
@Component
public class SysAspect {

    @Pointcut("execution(* com.baizhi.springbootshiro.controller.*.*(..))")
    public void pointCut() {

    }

    @Around("pointCut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {

        Object proceed = joinPoint.proceed();
        Signature signature = joinPoint.getSignature();
        MethodSignature methodSignature = ((MethodSignature) signature);
        Method method = methodSignature.getMethod();
        Annotation[] annotations = method.getDeclaredAnnotations();
        // TODO nothing
        String name = signature.getName();
        String typeName = signature.getDeclaringTypeName();
        log.info("signatureName:{}", name);
        log.info("signatureTypeName:{}", typeName);

        return proceed;
    }
}
